import 'package:flutter/material.dart';
import '../constants/hand_drawn_trigger_icon_type.dart';

class HandDrawnTriggerIcon extends StatelessWidget {
  final HandDrawnTriggerIconType type;
  final double size;
  final Color color;

  const HandDrawnTriggerIcon({
    Key? key,
    required this.type,
    this.size = 24,
    this.color = Colors.black,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      size: Size(size, size),
      painter: _HandDrawnTriggerIconPainter(
        type: type,
        color: color,
      ),
    );
  }
}

class _HandDrawnTriggerIconPainter extends CustomPainter {
  final HandDrawnTriggerIconType type;
  final Color color;

  _HandDrawnTriggerIconPainter({
    required this.type,
    required this.color,
  });

  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint()
      ..color = color
      ..style = PaintingStyle.stroke
      ..strokeWidth = 2.0
      ..strokeCap = StrokeCap.round;

    final center = Offset(size.width / 2, size.height / 2);
    final radius = size.width / 2 - 4;

    switch (type) {
      case HandDrawnTriggerIconType.work:
        _drawWorkIcon(canvas, size, paint);
        break;
      case HandDrawnTriggerIconType.home:
        _drawHomeIcon(canvas, size, paint);
        break;
      case HandDrawnTriggerIconType.social:
        _drawSocialIcon(canvas, size, paint);
        break;
      case HandDrawnTriggerIconType.other:
        _drawOtherIcon(canvas, size, paint);
        break;
    }
  }

  void _drawWorkIcon(Canvas canvas, Size size, Paint paint) {
    final path = Path();
    
    // 画一个手提包形状
    path.moveTo(size.width * 0.2, size.height * 0.4);
    path.lineTo(size.width * 0.2, size.height * 0.8);
    path.lineTo(size.width * 0.8, size.height * 0.8);
    path.lineTo(size.width * 0.8, size.height * 0.4);
    
    // 画提手
    path.moveTo(size.width * 0.35, size.height * 0.4);
    path.quadraticBezierTo(
      size.width * 0.5, size.height * 0.2,
      size.width * 0.65, size.height * 0.4
    );
    
    canvas.drawPath(path, paint);
  }

  void _drawHomeIcon(Canvas canvas, Size size, Paint paint) {
    final path = Path();
    
    // 画房子的轮廓
    path.moveTo(size.width * 0.2, size.height * 0.6);
    path.lineTo(size.width * 0.5, size.height * 0.2);
    path.lineTo(size.width * 0.8, size.height * 0.6);
    
    // 画房子的底部
    path.moveTo(size.width * 0.3, size.height * 0.5);
    path.lineTo(size.width * 0.3, size.height * 0.8);
    path.lineTo(size.width * 0.7, size.height * 0.8);
    path.lineTo(size.width * 0.7, size.height * 0.5);
    
    canvas.drawPath(path, paint);
  }

  void _drawSocialIcon(Canvas canvas, Size size, Paint paint) {
    // 画三个小人的简化轮廓
    
    // 中间的人
    canvas.drawCircle(
      Offset(size.width * 0.5, size.height * 0.3),
      size.width * 0.15,
      paint
    );
    canvas.drawLine(
      Offset(size.width * 0.5, size.height * 0.45),
      Offset(size.width * 0.5, size.height * 0.7),
      paint
    );
    
    // 左边的人
    canvas.drawCircle(
      Offset(size.width * 0.25, size.height * 0.4),
      size.width * 0.12,
      paint
    );
    canvas.drawLine(
      Offset(size.width * 0.25, size.height * 0.52),
      Offset(size.width * 0.25, size.height * 0.7),
      paint
    );
    
    // 右边的人
    canvas.drawCircle(
      Offset(size.width * 0.75, size.height * 0.4),
      size.width * 0.12,
      paint
    );
    canvas.drawLine(
      Offset(size.width * 0.75, size.height * 0.52),
      Offset(size.width * 0.75, size.height * 0.7),
      paint
    );
  }

  void _drawOtherIcon(Canvas canvas, Size size, Paint paint) {
    // 画三个点
    canvas.drawCircle(
      Offset(size.width * 0.2, size.height * 0.5),
      size.width * 0.08,
      paint
    );
    canvas.drawCircle(
      Offset(size.width * 0.5, size.height * 0.5),
      size.width * 0.08,
      paint
    );
    canvas.drawCircle(
      Offset(size.width * 0.8, size.height * 0.5),
      size.width * 0.08,
      paint
    );
  }

  @override
  bool shouldRepaint(_HandDrawnTriggerIconPainter oldDelegate) {
    return oldDelegate.type != type || oldDelegate.color != color;
  }
} 